<template>
  <div>
    <el-dialog
        title="修改信息"
        :visible.sync="dialogVisible"
        width="30%"
    >
      <span>
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="工号">
            <el-input v-model="form.dormitoryAdmin.account"></el-input>
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model="form.dormitoryAdmin.name"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="form.dormitoryAdmin.password"></el-input>
          </el-form-item>
          <el-form-item label="性别">
            <el-input v-model="form.dormitoryAdmin.gender"></el-input>
          </el-form-item>
       <el-form-item label="楼栋名称">
    <el-select v-model="form.dormitoryAdmin.buildingID" placeholder="请选择管理楼栋">
      <el-option   v-for="building in buildingList" :key="building.id" :label="building.name" :value="building.id"></el-option>
    </el-select>
  </el-form-item>
        </el-form>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="submit">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {_buildingAll, _dormAdminModify} from '../../../../api/super_admin'

export default {
  name: 'DormAdminEditDialog',
  created () {
    const DOT2 = {
      pageSize: 10000,
      pageNo: 1,
      data: {}
    }
    _buildingAll(DOT2).then(res => {
      if (res.status) {
        this.buildingList = res.data
      } else {
        this.$message({
          message: res.message,
          type: 'error'
        })
      }
    })
  },
  data () {
    return {
      dialogVisible: false,
      buildingList: [],
      form: {
        dormitoryAdmin: {
          password: '',
          name: '',
          gender: '',
          nation: '',
          account: '',
          buildingID: 0
        },
        buildingName: '西苑1舍'
      }
    }
  },
  methods: {
    show (DormAdmin) {
      this.dialogVisible = true
      this.form = JSON.parse(JSON.stringify(DormAdmin))
    },
    submit () {
      const OBJ = JSON.parse(JSON.stringify(this.form.dormitoryAdmin))
      for (let item in OBJ) {
        if (item === '') {
          this.$message({
            message: '所有字段非空',
            type: 'error'
          })
          return
        }
      }
      console.log(OBJ)
      _dormAdminModify(OBJ).then(res => {
        if (res.status) {
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.dialogVisible = false
          this.$emit('ok')
        } else {
          this.$message({
            message: '修改失败',
            type: 'warning'
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
